﻿package Welsy4.Connect.commands
{
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.commands.SequenceCommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import flash.net.URLVariables;
	
	
	import mx.rpc.IResponder;
	import mx.controls.Alert;
	
	import Welsy4.Connect.model.ConnectModel;
	import Welsy4.Connect.events.ChainEvent;
	import Welsy4.Connect.events.ResponseEvent;
	import Welsy4.Connect.events.MeetingEvent;
	import Welsy4.Connect.business.MeetingDelegate;
	import Welsy4.Connect.vo.HttpServiceHandler;
	import Welsy4.Connect.vo.SCOShortcut;
	import Welsy4.Connect.vo.Meeting;
	
	
	public class DeleteMeetingCommand extends SequenceCommand implements Command, IResponder
	{
		
		override public function execute(event:CairngormEvent):void {
			
			ConnectModel.getInstance().addQueue("DeleteMeetingCommand.execute");
			
			this.nextEvent = ChainEvent(event).nextChainedEvent;
			
			// UpdateMeetingCommand
			var meetingDelegate:MeetingDelegate = new MeetingDelegate(this);
			meetingDelegate.deleteMeeting(ConnectModel.getInstance().lastMeetingFound);
		}
		
		public function result(data:Object):void {
			
			ConnectModel.getInstance().addQueue("DeleteMeetingCommand.result");
		
			ConnectModel.getInstance().httpServiceHandler = new HttpServiceHandler();
			ConnectModel.getInstance().httpServiceHandler.setXML(data.result);
			
			if (ConnectModel.getInstance().httpServiceHandler.getResultStatus() == ConnectModel.SESSION_OK) {
				Alert.show("Deleted!\n" + data.result);
				
				this.executeNextCommand();
				
			} else {
			    CairngormEventDispatcher.getInstance().dispatchEvent(new ResponseEvent (ResponseEvent.ERROR, false, ResponseEvent.GENERIC, data.result));	
			}
		}
		
		public function fault(data:Object):void {
		    ConnectModel.getInstance().addQueue("DeleteMeetingCommand.fault");
			CairngormEventDispatcher.getInstance().dispatchEvent(new ResponseEvent (ResponseEvent.ERROR, false, ResponseEvent.CONNECTION));
		}
		
	}
	
}